package models

import (
	"github.com/astaxie/beego/orm"
)

func (a *BackendUser) TableName() string {
	return BackendUserTBName()
}

// BackendUserQueryParam 用于查询的类
type BackendUserQueryParam struct {
	BaseQueryParam
	UserNameLike string //模糊查询
	RealNameLike string //模糊查询
	Mobile       string //精确查询
	SearchStatus string //为空不查询，有值精确查询
}

// BackendUser 实体类
type BackendUser struct {
	Id                 int
	RealName           string `orm:"size(32)"`
	UserName           string `orm:"size(24)"`
	UserPwd            string `json:"-"`
	IsSuper            bool
	Status             int
	Mobile             string                `orm:"size(16)"`
	Email              string                `orm:"size(256)"`
	Avatar             string                `orm:"size(256)"`
	RoleIds            []int                 `orm:"-" form:"RoleIds"`
	RoleBackendUserRel []*RoleBackendUserRel `orm:"reverse(many)"` // 设置一对多的反向关系
	ResourceUrlForList []string              `orm:"-"`
	//CreateCourses      []*Course             `rom:"reverse(many)"` // 设置一对多的反向关系
}

// BackendUserOneByUserName 根据用户名密码获取单条
func BackendUserOneByUserName(username string, userpwd string) (*BackendUser, error) {
	m := BackendUser{}
	err := orm.NewOrm().QueryTable(BackendUserTBName()).Filter("username",username).Filter("userpwd",userpwd).One(&m)
	if err != nil {
		return nil,err
	}
	return &m,nil

}

func BackendUserOne (id int) (*BackendUser,error){
	o := orm.NewOrm()
	m := BackendUser{Id:id}
	err := o.Read(&m)
	if err != nil {
		return nil,err
	}
	return &m,nil
}